<template>
	<view>
		<view>
			<u--input placeholder="请输入书籍名称" border="surround" v-model="bookName"></u--input>
		</view>
		<view>
			<u--input placeholder="请输入书籍价格" border="surround" v-model="bookPrice"></u--input>
		</view>
		<view>
			<u-button type="primary" @click="addBook()">添加书籍</u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bookName: "",
				bookPrice: ""
			}
		},
		methods: {
			addBook() {
				if (this.bookName != undefined && this.bookName != null && this.bookName != '' && this.bookPrice !=
					undefined && this.bookPrice != null && this.bookPrice != '') {
					uni.$u.http.post('/book/addBook', {
						bookName: this.bookName,
						bookPrice: this.bookPrice
					}).then(res => {
						this.showToast();
						this.bookName = "";
						this.bookPrice = "";
					}).catch(err => {
						console.log(err);
					})
				}
			},
			showToast() {
				this.$refs.uToast.show({
					type: 'success',
					message: "添加成功",
					iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
				})
			}
		}

	}
</script>

<style>

</style>
